package com.example.supplychainbackend.entity;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "todo_item")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TodoEntity {

    @Id
    String	id;
    Boolean	completed;
    String	title;
    String	description;
    String	type;
    String	priority;
    String	deadline;
    String	creator;
    String  eid;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (id == null || id.equals("")) {
            id = String.format("%s%s%s%04d",
                    "TODO-E", eid, "-"+DateTimeUtils.getCurrentDateForID()+"-", counter.getAndIncrement());
        }
    }

}
